<template>
    <div>
        <table border="1px">
            <tr>
                <td>id</td>
                <td>名字</td>
                <td>操作</td>
            </tr>
            <tr v-for="i in catelist">
                <td>{{i.id}}</td>
                <td>{{i.name}}</td>
                <td><button @click="del(i.id)">删除</button>
                    <button @click="update(i.id)">修改</button></td>
            </tr>
        </table>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                catelist:[]
            }
        },
        methods:{
            getcate(){
                this.$axios.get('cateM').then(res=>{
                    if(res.data.code==200){
                        this.catelist = res.data.list
                    }
                })
            },
            del(id){
                this.$axios.delete('cateM?id='+id).then(res=>{
                    if(res.data.code==200){
                        alert('删除成功')
                        this.getcate()
                    }
                })
            },
            update(id){
                this.$axios.put('cateM?id='+id).then(res=>{
                    if(res.data.code==200){
                        alert('修改成功')
                        this.getcate()
                    }
                })
            }
        },
        mounted(){
            this.getcate()
        }
        
    }
</script>

<style scoped>

</style>